AC_PREREQ([2.4])
AC_INIT([tipcutils], [2.1.1], [parthasarathy.bhuvaragan@ericsson.com])

AM_INIT_AUTOMAKE([foreign])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL
AC_CHECK_PROG([has_pkg_config],[pkg-config],[yes])
if test "x$has_pkg_config" != "xyes"; then
	AC_MSG_ERROR([pkg-config not found])
fi

# Checks for header files.
AC_CHECK_HEADERS([linux/tipc.h])

# Use reproducible build date and time
if test "$SOURCE_DATE_EPOCH"; then
	DATE_FMT="%d %b %Y %H:%M:%S"
	BUILD_DATE=$(LC_ALL=C date -u -d "@$SOURCE_DATE_EPOCH" "+$DATE_FMT")
	AC_DEFINE_UNQUOTED([BUILD_DATE], ["$BUILD_DATE"], [Use reproducidle build date])
fi

# Checks for library functions.
PKG_CHECK_MODULES([LIBDAEMON], [libdaemon])
PKG_CHECK_MODULES([LIBMNL], [libmnl])
CFLAGS="$CFLAGS -I../../include -I../include -Wall -fno-strict-aliasing -fPIC"
LDFLAGS="$LDFLAGS ../../libtipc/libtipc.a -lpthread"

AC_CHECK_TYPE(struct tipc_sioc_ln_req, [tipc_lss=yes],[], [[#include <linux/tipc.h>]])
AM_CONDITIONAL(TIPC_LINK_STATE_SUBSCRITION, test "x$tipc_lss" = "xyes")

# Checks for TIPC GO API
AC_ARG_WITH(goapi,AS_HELP_STRING([--with-goapi],[Compile TIPC GO APIs examples]),[goapi=true],[])
if test "x$goapi" == "xtrue"; then
	AC_CHECK_PROG([gotool],[go],[true],[])
	if test "x$gotool" != "xtrue"; then
		AC_MSG_NOTICE([go tool not found - ignore compiling tipc go api example])
	fi
fi
AM_CONDITIONAL(TIPC_GOAPI_EXAMPLE, test "x$goapi" == "xtrue" -a "x$gotool" == "xtrue")

# Checks for TIPC JAVA API
AC_ARG_WITH(tipcj,AS_HELP_STRING([--with-tipcj],[Compile TIPC JAVA API and a couple of examples]),[with_tipcj=true],[])
if test "x$with_tipcj" == "xtrue"; then
	AC_CHECK_PROG([javac],[javac],[true],[])
	if test "x$javac" != "xtrue"; then
		AC_MSG_NOTICE([javac are not available - ignore java compiling])
	fi
fi
AM_CONDITIONAL(TIPC_JAVA, test "x$with_tipcj" == "xtrue" -a "x$javac" == "xtrue")

# Checks for TIPC PYTHON API
AC_ARG_WITH(py,AS_HELP_STRING([--with-py],[Compile TIPC PYTHON API and a couple of examples]),[pyapi=true],[])
if test "x$pyapi" == "xtrue"; then
	AM_PATH_PYTHON([3.0],[true],[])
	AC_CHECK_PROG([pyinstaller],[pyinstaller],[true],[$PYTHON_PATH])
	if test "x$pyinstaller" != "xtrue"; then
		AC_MSG_NOTICE([PyInstaller module not found - ignore compiling Python example])
	fi

fi
AM_CONDITIONAL([TIPC_PYTHON], [test "x$pyapi" == "xtrue" -a "x$PYTHON" != "xtrue"])
AM_CONDITIONAL([TIPC_STANDALONE], [test "x$pyapi" == "xtrue" -a "x$pyinstaller" == "xtrue"])

# Check if tipc-trace can be built as single executable file (i.e. preferred)
AM_PATH_PYTHON([2.7],, [:])
AC_CHECK_PROG([pyinstaller],[pyinstaller],[true])
AM_CONDITIONAL([TIPC_TRACE_EXE], [test "x$pyinstaller" == xtrue -a "$PYTHON" != :])
AM_COND_IF([TIPC_TRACE_EXE],,
           [AC_MSG_NOTICE([PyInstaller not found or Python version not appropriate - ignore building tipc-trace as single executable file])])

AC_CONFIG_FILES([
	Makefile
	libtipc/Makefile
	utils/Makefile
	utils/tipc-link-watcher/Makefile
	utils/tipclog/Makefile
	utils/net_topology_tracker/Makefile
	utils/tipc-trace/Makefile
	test/Makefile
	test/group_test/Makefile
	test/ptts/Makefile
	test/multicast_blast/Makefile
	test/overlapping_ranges/Makefile
	test/iovec/Makefile
	test/topsrv_stress/Makefile
	test/rdm/Makefile
	demos/Makefile
	demos/benchmark/Makefile
	demos/groupcast_demo/Makefile
	demos/connection_demo/Makefile
	demos/hello_world/Makefile
	demos/c_api_demo/Makefile
	demos/inventory_sim/Makefile
	demos/multicast_demo/Makefile
	demos/stream_demo/Makefile
	demos/topology_subscr_demo/Makefile
	demos/iov_control/Makefile
	demos/tipc-pipe/Makefile
	demos/golang/Makefile
	demos/golang/hello_world/Makefile
	demos/golang/connection/Makefile
	man/Makefile
	scripts/Makefile
	tipcj/Makefile
	demos/tipcj/Makefile
	demos/tipcj/hello_world/Makefile
	demos/tipcj/connection/Makefile
	pytipc/Makefile
	demos/pytipc/Makefile
	demos/pytipc/hello_world/Makefile
	demos/pytipc/connection/Makefile
	])
AM_CONDITIONAL(WITH_SCRIPTS, false)
AC_ARG_ENABLE(scripts,
        [  --enable-scripts  Install utility scripts in sysconfdir],
	 AM_CONDITIONAL(WITH_SCRIPTS, true))

AC_OUTPUT
